package com.zhang.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.zhang.springcloud.entities.CommonResult;
import com.zhang.springcloud.entities.Payment;
import com.zhang.springcloud.sentinel.BlockHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RateLimitController {

    @GetMapping("/byResource")
    @SentinelResource(value = "byResource",blockHandlerClass = BlockHandler.class,blockHandler = "handleException")
    public CommonResult byResource() {
        return new CommonResult(200,"按资源限定名称限流测试OK",new Payment(1L,"200"));
    }


    @GetMapping("/byResource1")
    @SentinelResource(value = "byResource1",blockHandlerClass = BlockHandler.class,blockHandler = "handleException1")
    public CommonResult byResource1() {
        return new CommonResult(200,"按资源限定名称限流测试OK",new Payment(1L,"201"));
    }
}